﻿using Liju.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace LiJu.Db
{
    /// <summary>
    /// 再次送钉判定
    /// </summary>
    public class SongDingJudgeDbHelper
    {
        /// <summary>
        /// 获取再次送钉记录
        /// </summary>
        /// <returns></returns>
        public static List<SongDingJudgeModel> GetSongDingAgainList()
        {
            string strMySql = $"select * from SongDingJudge ";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            return DbExtension.DataTableToList<SongDingJudgeModel>(dt);
        }

        /// <summary>
        /// 添加再次送钉记录
        /// </summary>
        /// <returns></returns>
        public static Int64 SongDingAgainAdd(SongDingJudgeModel songDingAgainModel)
        {
            string strMySql = $"INSERT INTO SongDingJudge (ProductSN, WorkNo, TaskID, OperateType, IssueType, ReMark, JudgeGongHao, " +
                $"JudgeUserName, CreateTime) VALUES('{songDingAgainModel.ProductSN}',{songDingAgainModel.WorkNo},{songDingAgainModel.TaskID}," +
                $"'{songDingAgainModel.OperateType}', '{songDingAgainModel.IssueType}','{songDingAgainModel.ReMark}', " +
                $"'{songDingAgainModel.JudgeGongHao}','{songDingAgainModel.JudgeUserName}', '{songDingAgainModel.CreateTime}');select @@IDENTITY ";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            if (dt != null && dt.Rows.Count > 0)
            {
                return Convert.ToInt64(dt.Rows[0][0]);
            }
            else
            {
                return -1;
            }
        }

        /// <summary>
        /// 更新再次送钉 送钉时间
        /// </summary>
        /// <returns></returns>
        public static int SongDingAgainUpdate(Int64 logID, int nState)
        {
            string strMySql = "update SongDingJudge set State=" + nState + ", UpdateTime='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+
                "' where LogID="+ logID + "; ";
            return DalMySQL.ExecuteNonQuery(strMySql);
        }

    }
}
